﻿<%@ WebHandler Language="C#" Class="ImageQC" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.IO;
using System.Linq;
using Biz_Dal;
using Biz_Dal.Dal;
using Biz_Dal.Biz;

public class ImageQC : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        string id = context.Request.QueryString["Id"];
        context.Response.ContentType = "image/jpeg";
        Stream strm = ShowEmpImage(id);
        byte[] buffer = new byte[4096];
        int byteSeq = strm.Read(buffer, 0, 4096);
        while (byteSeq > 0)
        {
            context.Response.OutputStream.Write(buffer, 0, byteSeq);
            byteSeq = strm.Read(buffer, 0, 4096);
        }
    }

    public Stream ShowEmpImage(string id)
    {
        int idS = Convert.ToInt32(id);
        DalCommon context1 = new DalCommon();
        var r = (from a in context1.BookIdeas_ShopDataContext.QuangCaos
                 where a.idQuangCao == idS
                 select a).First();
        return new MemoryStream(r.hinhQuangCao.ToArray());
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }


}